﻿/*******************************************************
*类名称：WechatAutoReplyManager
*版本号：V1.0.0.0
*作者：成俊杰
*CLR版本：4.0.30319.36264
*创建时间：2017-09-18 13:44:05
*说明：T_WechatAutoReply管理类
*更新备注：
**********************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wechat.Dao;
using Wechat.Domain;
using Wechat.Dto.Request;
using Wechat.Util.ReturnMessage;
using Wechat.Util.StateCode;

namespace Wechat.Manager.Implement
{
    /// <summary>
    /// T_WechatAutoReply
    /// </summary>
    public class WechatAutoReplyManager : GenericManagerBase<WechatAutoReply>, IWechatAutoReplyManager
    {
        public IWechatAutoReplyRepository WechatAutoReplyRepository { get; set; }
        /// <summary>
        /// 获取微信关注时默认回复
        /// </summary>
        /// <returns></returns>
        public ResultMessage GetWechatAutoReplyModel()
        {
            ResultMessage returnMsg = new ResultMessage()
            {
                Status = false,
                Message = "查询关注时默认回复失败"
            };
            var AutoReplyModel = WechatAutoReplyRepository.GetAll().OrderByDescending(reply=>reply.AutoReplyId).FirstOrDefault();

            if (AutoReplyModel != null)
            {
                returnMsg.Status = true;
                returnMsg.Data = AutoReplyModel;
                returnMsg.Code = (int)EnumApiStateCode.Success;
                returnMsg.Message = "查询关注时默认回复成功";
            }

            return returnMsg;
        }

        /// <summary>
        /// 添加关注时默认回复
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ResultMessage InsertOrUpdateAutoReply(WechatAutoReplyRequest request)
        {
            ResultMessage returnMsg = new ResultMessage()
            {
                Status = false,
                Message = request.AutoReplyId > 0 ? "修改关注时默认回复失败" : "添加关注时默认回复失败"
            };
            var result = WechatAutoReplyRepository.InsertOrUpdateAutoReply(request);

            if (result > 0)
            {
                returnMsg.Data = result;
                returnMsg.Code = (int)EnumApiStateCode.Success;
                returnMsg.Message = request.AutoReplyId > 0 ? "修改关注时默认回复成功" : "添加关注时默认回复成功";
                returnMsg.Status = true;
            }
            return returnMsg;
        }
    
    }
}